package com.github.permissiondog.cancanpbackend.filter;

import com.github.permissiondog.cancanpbackend.util.JSON;

import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;
import javax.json.bind.JsonbConfig;
import javax.json.bind.serializer.DeserializationContext;
import javax.json.bind.serializer.JsonbDeserializer;
import javax.json.bind.serializer.JsonbSerializer;
import javax.json.bind.serializer.SerializationContext;
import javax.json.stream.JsonGenerator;
import javax.json.stream.JsonParser;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Type;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class BaseFilter extends HttpFilter {
    //格式转换
    protected void json(HttpServletResponse res, Object obj) throws IOException {
        res.setCharacterEncoding("utf-8");
        res.setContentType("application/json");
        JSON.JSONB.toJson(obj, res.getWriter());
    }
}
